package cn.t.core.exception;


import cn.t.core.util.I18nUtils;
import cn.t.core.util.SpringContextUtil;
import lombok.Getter;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

import java.util.Locale;

/**
 * @author l
 */
@Getter
public class BizException extends RuntimeException {

    /**
     * 带占位符的异常
     */
    public BizException(BaseError error) {
      super(I18nUtils.getMessage(error.getCode().toString(), null));
        this.code = error.getCode();
    }

    /**
     * 带占位符的构造函数，尽在message文件中定义的code带有%s时使用
     */
    public BizException(BaseError error, Object ...messages) {
  super(I18nUtils.getMessage(error.getCode().toString(), messages));
        this.code = error.getCode();
        if (messages != null && messages.length > 0) {
            this.messages = messages;
        }
    }



    public Integer getCode() {
        return code;
    }

    private Integer code;

    private Object[] messages;

}
